package test;

public class Test20210326 {
    public static int charToInt(char c) throws Exception {
        switch(c){
            case 'I':return 1;
            case 'V':return 5;
            case 'X':return 10;
            case 'L':return 50;
            case 'C':return 100;
            case 'D':return 500;
            case 'M':return 1000;
            default:throw new Exception("the acceptMessage error");
        }
    }
    public static int test(String s) throws Exception {
        int []convertInt = new int[s.length()];
        int index = 0;

        char[] a = s.toCharArray();
        //将字母代表的数字存储起来
       for(char element:a){
           convertInt[index++] =charToInt(element);
       }
       int sum = convertInt[0];
       for( int i = 1;i<convertInt.length;i++){
           if(convertInt[i]<=convertInt[i-1]){
               sum = sum+convertInt[i];
           }
           if(convertInt[i]>convertInt[i-1]){
               sum = sum-convertInt[i];
           }
       }
       return sum;
    }

    public static void main(String[] args) {
        String s = "CCLVI";
        int a = 0;
        try {
             a =  test(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(a);
    }
}
